package cn.dujc.superkid.adapter;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

import com.zhy.view.flowlayout.FlowLayout;

import java.util.List;

import cn.dujc.superkid.R;
import cn.dujc.superkid.fragment.UtilFragment;

public class UtilAdapter extends RecyclerView.Adapter<UtilAdapter.ViewHolder>{
    private List<String> followList;
    private FlowLayout flowLayout;
    private static final String TAG = UtilFragment.class.getName();
    public UtilAdapter(List<String> followList) {
        this.followList = followList;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_grade, parent, false);
        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.gradeTitle.setText(followList.get(position));
        flowLayout.removeAllViews();
        for (int x=0;x<followList.size();x++) {
            CheckBox checkBox = (CheckBox) View.inflate(this.flowLayout.getContext(), R.layout.item_flowlayout, null);
            checkBox.setText("2017年高考语文试题");
            final int finalX = x;
            checkBox.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Log.i(TAG, "onClick: =============");
                }
            });
            flowLayout.addView(checkBox);
        }
    }

    @Override
    public int getItemCount() {
        return followList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView gradeTitle;
        public ViewHolder(View itemView) {
            super(itemView);
            gradeTitle = itemView.findViewById(R.id.tv_gradeTitle);
            flowLayout = itemView.findViewById(R.id.flowlayout);
        }
    }
}
